package com.lht.testDemo.spring.expressionLanguage;

import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import java.util.Arrays;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-07-24
 */
public class ELTest {

    @Test
    public void test() {

        ExpressionParser parser = new SpelExpressionParser();
        Expression expres = parser.parseExpression("'helloworld'");
        System.out.println(expres.getValue());

    }

    @Test
    public void test1() {

        ExpressionParser parser = new SpelExpressionParser();
        Expression expres = parser.parseExpression("'helloworld'.concat('!')");
        System.out.println(expres.getValue());

    }

    @Test
    public void test2() {
        ExpressionParser parser = new SpelExpressionParser();
        Expression e = parser.parseExpression("'helloworld'.bytes");
        System.out.println(Arrays.toString((byte[]) e.getValue()));
    }

    @Test
    public void test3() {
        ExpressionParser parser = new SpelExpressionParser();
        Expression e = parser.parseExpression("'helloworld'.bytes.length");
        System.out.println(e.getValue());
    }

    @Test
    public void test4() {
        ExpressionParser parser = new SpelExpressionParser();
        Expression e= parser.parseExpression("new String('hello world').toUpperCase()");
        System.out.println(e.getValue());
    }

}
